import { createContext, useState, useContext } from 'react'

const TodoContext = createContext();
// 自定义hooks函数,函数名都以use开头
export const useTodo = () => useContext(TodoContext)

// export { TodoContext }

const TodoProvider = ({ children }) => {
    const [list, setList] = useState([]);
    const handleList = (text) => {
        setList([...list, { title: text, time: new Date().toLocaleString() }])
    }
    return (
        <TodoContext.Provider 
            value={{ list, handleList }}
        >
            {children}
        </TodoContext.Provider>
    )
}

export default TodoProvider;